/*
按列填充
*/

// 沿着X轴平移
mat4 translationX(float x){
    return mat4(
        1.,0.,0.,0.,
        0.,1.,0.,0.,
        0.,0.,1.,0.,
        x,0.,0.,1.
    );
}
// 沿着Y轴平移
mat4 translationY(float y){
    return mat4(
        1.,0.,0.,0.,
        0.,1.,0.,0.,
        0.,0.,1.,0.,
        0.,y,0.,1.
    );
}
// 沿着Z轴平移
mat4 translationZ(float z){
    return mat4(
        1.,0.,0.,0.,
        0.,1.,0.,0.,
        0.,0.,1.,0.,
        0.,0.,z,1.
    );
}
// 绕任意轴平移
mat4 translation(vec3 vector){
    float x=vector.x;
    float y=vector.y;
    float z=vector.z;
    return mat4(
        1.,0.,0.,0.,
        0.,1.,0.,0.,
        0.,0.,1.,0.,
        x,y,z,1.
    );
}
// 沿着X轴缩放
mat4 scaleX(float x){
    return mat4(
        x,0.,0.,0.,
        0.,1.,0.,0.,
        0.,0.,1.,0.,
        0.,0.,0.,1.
    );
}
// 沿着Y轴缩放
mat4 scaleY(float y){
    return mat4(
        1.,0.,0.,0.,
        0.,y,0.,0.,
        0.,0.,1.,0.,
        0.,0.,0.,1.
    );
}
// 沿着Z轴缩放
mat4 scaleZ(float z){
    return mat4(
        1.,0.,0.,0.,
        0.,1.,0.,0.,
        0.,0.,z,0.,
        0.,0.,0.,1.
    );
}
// 绕任意轴缩放
mat4 scale(vec3 vector){
    float x=vector.x;
    float y=vector.y;
    float z=vector.z;
    return mat4(
        x,0.,0.,0.,
        0.,y,0.,0.,
        0.,0.,z,0.,
        0.,0.,0.,1.
    );
}
// 绕X轴旋转
mat4 rotateX(float angle){
    float radian=radians(angle);
    float s=sin(radian);
    float c=cos(radian);
    // 按列填充
    return mat4(
        1.,0.,0.,0.,// 第一列
        0.,c,-s,0.,// 第二列
        0.,s,c,0.,// 第三列
        0.,0.,0.,1.// 第四列
    );
}
// 绕Y轴旋转
mat4 rotateY(float angle){
    float radian=radians(angle);
    float s=sin(radian);
    float c=cos(radian);
    // 按列填充
    return mat4(
        c,0.,s,0.,// 第一列
        0.,1.,0.,0.,// 第二列
        -s,0.,c,0.,// 第三列
        0.,0.,0.,1.// 第四列
    );
}
// 绕Z轴旋转
mat4 rotateZ(float angle){
    float radian=radians(angle);
    float s=sin(radian);
    float c=cos(radian);
    // 按列填充
    return mat4(
        c,-s,0.,0.,// 第一列
        s,c,0.,0.,// 第二列
        0.,0.,1.,0.,// 第三列
        0.,0.,0.,1.// 第四列
    );
}
// 绕任意轴旋转
mat4 rotate(vec3 axis,float angle){
    float x=axis.x,y=axis.y,z=axis.z;
    float radian=radians(angle);
    float s=sin(radian),c=cos(radian);
    float t=1.-c;
    float m0=x*x*t+c,
    m1=x*y*t-z*s,
    m2=x*z*t+y*s,
    m3=0.,
    m4=y*x*t+z*s,
    m5=y*y*t+c,
    m6=y*z*t-x*s,
    m7=0.,
    m8=z*x*t-y*s,
    m9=z*y*t+x*s,
    m10=z*z*t+c,
    m11=0.,
    m12=0.,
    m13=0.,
    m14=0.,
    m15=1.;
    // 按列填充
    return mat4(
        m0,m1,m2,m3,// 第一列
        m4,m5,m6,m7,// 第二列
        m8,m9,m10,m11,// 第三列
        m12,m13,m14,m15// 第四列
    );
}
// 沿着X轴镜像
mat4 mirrorX(){
    return mat4(
        -1.,0.,0.,0.,
        0.,1.,0.,0.,
        0.,0.,1.,0.,
        0.,0.,0.,1.
    );
}
// 沿着Y轴镜像
mat4 mirrorY(){
    return mat4(
        1.,0.,0.,0.,
        0.,-1.,0.,0.,
        0.,0.,1.,0.,
        0.,0.,0.,1.
    );
}
// 沿着Z轴镜像
mat4 mirrorZ(){
    return mat4(
        1.,0.,0.,0.,
        0.,1.,0.,0.,
        0.,0.,-1.,0.,
        0.,0.,0.,1.
    );
}
// 指定轴镜像
mat4 mirror(vec3 axis){
    axis=normalize(axis);
    float x=axis.x,y=axis.y,z=axis.z;
    return mat4(
        1.-2.*x*x,-2.*x*y,-2.*x*z,0.,
        -2.*x*y,1.-2.*y*y,-2.*z*y,0.,
        -2.*x*z,-2.*y*z,1.-2.*z*z,0.,
        0.,0.,0.,1.
    );
}

// 沿着X错切
mat4 shearX(vec2 axis){
    float xy=axis.x,xz=axis.y;
    return mat4(
        1.,0.,0.,0.,
        xy,1.,0.,0.,
        xz,0.,1.,0.,
        0.,0.,0.,1.
    );
}
// 沿着Y错切
mat4 shearY(vec2 axis){
    float yx=axis.x,yz=axis.y;
    return mat4(
        1.,yx,0.,0.,
        0.,1.,0.,0.,
        0.,yz,1.,0.,
        0.,0.,0.,1.
    );
}
// 沿着Z错切
mat4 shearZ(vec2 axis){
    float zx=axis.x,zy=axis.y;
    return mat4(
        1.,0.,zx,0.,
        0.,1.,zy,0.,
        0.,0.,1.,0.,
        0.,0.,0.,1.
    );
}
// 指定轴错切
mat4 shear(vec2 axisX,vec2 axisY,vec2 axisZ){
    float xy=axisX.x,xz=axisX.y;
    float yx=axisY.x,yz=axisY.y;
    float zx=axisZ.x,zy=axisZ.y;
    return mat4(
        1.,yx,zx,0.,
        xy,1.,zy,0.,
        xz,yz,1.,0.,
        0.,0.,0.,1.
    );
}
